//=============================================================================
// PlasmaGunProjectile.
//=============================================================================
class PlasmaGunProjectile extends LinkProjectile
	placeable;

#exec OBJ LOAD FILE=XEffectMat.utx
#exec obj load file=..\Sounds\WeaponSounds.uax

var xEmitter xTrail;
/*var int Links;



replication
{
    unreliable if (bNetInitial && Role == ROLE_Authority)
        Links;
}
*/
simulated function Destroyed()
{
    if (xTrail != None)
    {
        xTrail.Destroy();
    }
	Super.Destroyed();
}

simulated function PostBeginPlay()
{
    local Rotator R;

	Super.PostBeginPlay();

    if ( EffectIsRelevant(vect(0,0,0),false) )
		xTrail = Spawn(class'PlasmaProjEffect',self);

	Velocity = Vector(Rotation);
    Acceleration = Velocity * 3000.0;
    Velocity *= Speed;

    R = Rotation;
    R.Roll = Rand(65536);
    SetRotation(R);

    if ( Level.bDropDetail )
	{
		bDynamicLight = false;
		LightType = LT_None;
	}
}

simulated function LinkAdjust()
{
//    local float ls;
//
//    if (Links > 0)
//    {
//        ls = class'LinkFire'.default.LinkScale[Min(Links,5)];
//
//        SetDrawScale3D(default.DrawScale3D * (ls + 0.5));
//
//    	if ( Trail != None )
//        {
//            Trail.mLifeRange[0] *= (ls + 1);
//            Trail.mLifeRange[1] = Trail.mLifeRange[0];
//
//            Trail.mSizeRange[0] *= (ls + 1);
//            Trail.mSizeRange[1] = Trail.mSizeRange[0];
//
//            Trail.mPosDev.Y *= (ls + 1);
//            Trail.mPosDev.Z = Trail.mPosDev.Y;
//
//            Trail.Skins = Texture'XEffectMat.Link.link_muz_blue';
//            Trail.Skins[0] = FinalBlend'TFMedia.Plasma_Muz_blueFB';
//        }
//
//        Speed = default.Speed + 200*3;
//        MaxSpeed = default.MaxSpeed + 350*3;
//	    Velocity = Speed * Vector(Rotation);
//
//        SetCollisionSize(ls*10, ls*10);
//
//        Skins[0] = FinalBlend'TFMedia.Plasma_Muz_blueFB';
        LightHue = 150;
//    }
}

simulated function PostNetBeginPlay()
{
    if (Role < ROLE_Authority)
        LinkAdjust();
	if ( Level.bDropDetail || Level.DetailMode == DM_Low )
		LightType = LT_None;
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
    if ( EffectIsRelevant(Location,false) )
	{
//        if (Links == 0)
            Spawn(class'PlasmaProjSparks',,, HitLocation, rotator(HitNormal));
//        else
//            Spawn(class'PlasmaProjSparks',,, HitLocation, rotator(HitNormal));
	}
    PlaySound(Sound'WeaponSounds.PulseRifle.PulseRifleAltFire');
	Destroy();
}

simulated function ProcessTouch (Actor Other, vector HitLocation)
{
    local Vector X, RefNormal, RefDir;

	if (Other == Instigator) return;
    if (Other == Owner) return;

    if (Other.IsA('xPawn') && xPawn(Other).CheckReflect(HitLocation, RefNormal, Damage*0.25))
    {
        if (Role == ROLE_Authority)
        {
            X = Normal(Velocity);
            RefDir = X - 2.0*RefNormal*(X dot RefNormal);
            //Log("reflecting off"@Other@X@RefDir);
            Spawn(Class, Other,, HitLocation+RefDir*20, Rotator(RefDir));
        }
        Destroy();
    }
    else if ( !Other.IsA('Projectile') || Other.bProjTarget )
	{
		if ( Role == ROLE_Authority )
			Other.TakeDamage(Damage * (1.0 + float(Links)),Instigator,HitLocation,MomentumTransfer * (1.0 + float(Links)*0.25) * Normal(Velocity),MyDamageType);
		Explode(HitLocation, vect(0,0,1));
	}
}

defaultproperties
{
     Speed=2000.000000
     Damage=5.000000
     MomentumTransfer=15000.000000
     MyDamageType=Class'Taskforces.PlasmaGunDamType'
     LightHue=150
     LightSaturation=128
     LightBrightness=160.000000
     LifeSpan=4.000000
     DrawScale3D=(X=2.550000,Y=1.700000,Z=1.700000)
     Skins(0)=FinalBlend'TFMedia.PlasmaGun.Plasma_Muz_blueFB'
}
